<!--
 * @Descripttion: 
 * @version: 
 * @Author: ada.wu
 * @Date: 2025-06-25 23:48:14
 * @LastEditors: ada.wu
 * @LastEditTime: 2025-07-07 22:37:50
-->
<style>
    .top-panel>.layui-card-body {
        height: 130px;
    }

    .date-input {
        width: 200px;
    }
</style>
<div class="layuimini-container layuimini-page-anim">
    <!-- 用于创建子页面 -->
    <div class="page-create"></div>

    <!-- page-main-create -->
    <!-- 用于显示 隐藏 -->
    <div class="layuimini-main page-main-create">
        <div class="layuimini-title">
            <div class="flex items-center">
                <h4><span>劳动力作业报表</span></h4>
                <input type="text" name="datePeriodStart" autocomplete="off" id="date_period"
                    class="layui-input date-input ml-3" placeholder="请选择" />
            </div>
        </div>
        <div class="m-df">
            <form class="layui-form" action="" lay-filter="search-form">
                <div class="layui-form-item">
                    <div class="search-box-wrapper">
                        <div class="search-box-body">
                            <div class="layui-inline">
                                <label class="layui-form-label">关联业务</label>
                                <div class="layui-input-inline">
                                    <select class="layui-input" lay-append-to="body" placeholder="请选择"
                                        name="businessNames" lay-search>
                                        <option value="1">清扫保洁</option>
                                        <option value="2">绿化养护</option>
                                        <option value="3">设施维护</option>
                                        <option value="4">其他</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">所属组织</label>
                                <div class="layui-input-inline">
                                    <select class="layui-input" lay-append-to="body" placeholder="请选择"
                                        name="businessNames" lay-search>
                                        <option value="1">清扫保洁</option>
                                        <option value="2">绿化养护</option>
                                        <option value="3">设施维护</option>
                                        <option value="4">其他</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">所属网格</label>
                                <div class="layui-input-inline">
                                    <select class="layui-input" lay-append-to="body" placeholder="请选择"
                                        name="businessNames" lay-search>
                                        <option value="1">清扫保洁</option>
                                        <option value="2">绿化养护</option>
                                        <option value="3">设施维护</option>
                                        <option value="4">其他</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="search-box-btns">
                            <button type="submit" class="layui-btn layui-btn-sm" lay-submit
                                lay-filter="data-search-btn">查询</button>
                            <button type="reset" class="layui-btn  layui-btn-sm layui-btn-primary">重置</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div class="section">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-xs12 layui-col-md6">
                    <div class="layui-card top-panel noborder" lay-on="work_completion">
                        <div class="layui-card-header font-weight">作业完成率</div>
                        <div class="layui-card-body">
                            <div class="layui-row layui-col-space5 flex-center">
                                <div class="layui-col-xs6 layui-col-md6">
                                    <div class="top-panel-content justify-center">
                                        <div class="outer-circle">
                                            <div class="progress-circle">
                                                <div id="scheduling_rate" class="pie-chart"></div>
                                            </div>
                                            <div class="process-format">
                                                <text id="scheduling_rate_text">0</text>
                                                <span>%</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-xs6 layui-col-md6 t-c">
                                    <div class="flex justify-center flex-1">
                                        <div>
                                            <div class="layui-font-gray">实际作业数</div>
                                            <div class="layui-font-black">0</div>
                                        </div>
                                        <div class="layui-font-gray pl-4 pr-4">/</div>
                                        <div>
                                            <div class="layui-font-gray">计划作业数</div>
                                            <div class="layui-font-black">0</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-md6">
                    <div class="layui-card top-panel noborder" lay-on="work_coverage">
                        <div class="layui-card-header font-weight">作业覆盖率</div>
                        <div class="layui-card-body">
                            <div class="layui-row layui-col-space5 flex-center">
                                <div class="layui-col-xs6 layui-col-md6">
                                    <div class="top-panel-content justify-center">
                                        <div class="outer-circle">
                                            <div class="progress-circle">
                                                <div id="attendance_rate" class="pie-chart"></div>
                                            </div>
                                            <div class="process-format">
                                                <text id="attendance_rate_text">0</text>
                                                <span>%</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-xs6 layui-col-md6 t-c">
                                    <div class="flex justify-center flex-1">
                                        <div>
                                            <div class="layui-font-gray">有效作业里程(公里)</div>
                                            <div class="layui-font-black">0</div>
                                        </div>
                                        <div class="layui-font-gray pl-4 pr-4">/</div>
                                        <div>
                                            <div class="layui-font-gray">计划作业里程(公里)</div>
                                            <div class="layui-font-black">0</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="section">
            <div class="title-row">
                <div class="title-left">
                    <div class="title-info">
                        <div class="title-line"></div>
                        <span class="title-text">劳动力作业数据</span>
                    </div>
                </div>
                <div class="title-right" style="flex: auto;">
                    <span class="title-right-text">
                        <form class="layui-form" action="" lay-filter="search-form">
                            <div class="layui-form-item mb-0 ">
                                <div class="layui-inline">
                                    <label class="layui-form-label">计划名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" placeholder="请输入" name="name" autocomplete="off"
                                            class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">计划名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" placeholder="请输入" name="name" autocomplete="off"
                                            class="layui-input">
                                    </div>
                                </div>
                            </div>
                        </form>


                    </span>
                </div>
            </div>
        </div>
        <div class="section  table-stripe">
            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        </div>

    </div>
</div>
<script>
    layui.use(['form', 'table', 'miniPage', 'echarts'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            layer = layui.layer,
            util = layui.util,
            echarts = layui.echarts,
            miniPage = layui.miniPage;
        function updatePieChart(elementId, percent, textId = null) {
            const chart = echarts.init(document.getElementById(elementId));
            if (!chart) return;

            if (textId) {
                const textDom = document.getElementById(textId);
                if (textDom) {
                    textDom.innerText = percent;
                }
            }

            var option = {
                series: [{
                    type: 'pie',
                    radius: ['80%', '100%'],
                    label: {
                        show: false,
                    },
                    data: [
                        { value: percent, name: '排班率', itemStyle: { color: '#0080FF' } },
                        { value: 100 - percent, name: '未完成', itemStyle: { color: '#e0e0e0' } }
                    ],
                    hoverAnimation: false,
                    labelLine: {
                        show: false
                    }
                }]
            };
            chart.setOption(option);
            window.onresize = function () {
                chart.resize();
            }
        }

        updatePieChart('scheduling_rate', 15, 'scheduling_rate_text');
        updatePieChart('attendance_rate', 75, 'attendance_rate_text');
        /******************** 渲染组件 start ********************/
        form.render('select'); //刷新select选择框渲染
        // 起始日期
        laydate.render({
            elem: '#date_period',
            range: true
        });
        util.on('lay-on', {
            // 完成率
            'work_coverage': function () {
                console.log('完成率===')
                miniPage.renderPageCreate('page/laborOperations/laborWorkList/components/workDetail.html')
            },
            //覆盖率
            'work_completion': function () {
                console.log('覆盖率==')
                // miniPage.renderPageCreate('page/laborOperations/laborJobManager/components/map.html')
                miniPage.renderPageCreate('page/laborOperations/laborWorkList/components/workDetail.html')
            }
        })


        /******************** 渲染组件 end ********************/



        table.render({
            elem: '#currentTableId',
            url: 'api/table.json',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter'],
            cols: [[
                { field: 'name', minWidth: 180, title: '姓名' },
                { field: 'score', minWidth: 180, title: '总出勤里程(公里)', sort: true },
                { field: 'score', minWidth: 180, title: '计划作业次数/里程' },
                { field: 'score', minWidth: 180, title: '实际作业次数/里程' },
                { field: 'score', minWidth: 140, title: '作业覆盖率', sort: true },
                { field: 'score', minWidth: 100, title: '计划任务数' },
                { field: 'score', minWidth: 100, title: '作业任务数' },
                { title: '操作', minWidth: 100, toolbar: '#currentTableBar', align: "center" }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'grid',
            size: 'lg'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar事件监听
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {   // 监听添加操作
                var content = miniPage.getHrefContent('page/table/add.html');
                var openWH = miniPage.getOpenWidthHeight();

                var index = layer.open({
                    title: '添加用户',
                    type: 1,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: [openWH[0] + 'px', openWH[1] + 'px'],
                    offset: [openWH[2] + 'px', openWH[3] + 'px'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });
    });



</script>